package com.example.administrator.yuejian35.Home.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.yuejian35.Home.bean.Course;
import com.example.administrator.yuejian35.R;

import butterknife.ButterKnife;

import static com.example.administrator.yuejian35.Config.CourseImages_URL;
import static com.example.administrator.yuejian35.Config.Video_URL;

/**
 * Created by GUO on 2015/12/3.
 */
public class RecyclerItemViewHolder extends RecyclerItemBaseHolder {

    public final static String TAG = "RecyclerView2List";

    protected Context context = null;
   // @BindView(R.id.list_item_container)
    FrameLayout listItemContainer;
    //@BindView(R.id.list_item_btn)
    //ImageView listItemBtn;

    ImageView imageView;
    public TextView name;
    public ImageView pic;
    public TextView apply;


    public RecyclerItemViewHolder(Context context, View v) {
        super(v);
        this.context = context;
        ButterKnife.bind(this, v);
        imageView = new ImageView(context);

        listItemContainer = (FrameLayout) v.findViewById(R.id.list_item_container);
        name = (TextView) itemView.findViewById(R.id.course_name);
        apply= (TextView) itemView.findViewById(R.id.course_apply);
        pic= (ImageView) itemView.findViewById(R.id.course_pic);
    }

    public void onBind(final int position, final Course course) {

        //增加封面
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setImageResource(R.drawable.lunbotu);
        Uri uri = Uri.parse(CourseImages_URL+course.getCoursepic());
        imageView.setImageURI(uri);

        listVideoUtil.addVideoPlayer(position, imageView, TAG, listItemContainer, pic);

        pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                name.setText("");
                apply.setText("");
                getRecyclerBaseAdapter().notifyDataSetChanged();
                //listVideoUtil.setLoop(true);
                listVideoUtil.setPlayPositionAndTag(position, TAG);
                listVideoUtil.setTitle("title " + course.getCoursename());
                String url;
                if (course.getCourseid().equals("")) {
                    url = Video_URL+"video1.mp4";
                } else {
                    url = "http://baobab.wdjcdn.com/14564977406580.mp4";
                }
                //listVideoUtil.setCachePath(new File(FileUtils.getPath()));
                listVideoUtil.startPlay(url);

                //必须在startPlay之后设置才能生效
                //listVideoUtil.getGsyVideoPlayer().getTitleTextView().setVisibility(View.VISIBLE);
            }
        });
    }

}





